<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>订单记录</title>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/font-awesome.min.css" rel="stylesheet">
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <!-- <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/iscroll.js"></script> -->
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/store/css/cart.css?v=1.3.0"/>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/exchange_order_list.css" rel="stylesheet">
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
</head>
<body>
<div id="box_cart">
    <div class="wrap scroll" id="wrapper">
        <div class="cart">
            <ul class="cart_ul" id="cart_ul_1"></ul>
            <ul class="cart_ul" id="cart_ul_2"></ul>
            <div class="more" abc="">
                <div class="more_center">
                    <i class="pull_icon"></i>
                    <span>上拉加载...</span>
                </div>
            </div>
            <div class="lis_em">
                <div class="no_em">
                    <div class="no_img">
                        <img src="/img/00013.png">
                    </div>
                </div>
                <p class="lis_wrods"></p>
            </div>
        </div>
    </div>
    <ul class="navbar">
            <li class="nav_li on" id="nav_li_buy">
                <i class="fa fa-cart-arrow-down"></i>
                我买的
            </li>
            <li class="nav_li" id="nav_li_sell">
                <i class="fa fa-shopping-cart"></i>
                我卖的
            </li>
        </ul>
</div>

</body>
<script>
     /*滚动*/
    var page = 0;
    var type = 0;
    /*滚动*/
    // var myScroll;
    // function loaded () {
    //     setTimeout(function(){
    //         myScroll = new IScroll('.wrap', {
    //             mouseWheel: true,
    //             click: true
    //         });
    //     },100);
    // }
    var overscroll = function(el){ 
        el.addEventListener('touchstart', function(){ 
        var top = el.scrollTop; 
        var totalScroll = el.scrollHeight; 
        var currentScroll = top + el.offsetHeight; 
        if(top === 0) { 
            el.scrollTop = 1; 
        }else if(currentScroll === totalScroll){ 
            el.scrollTop = top - 1; 
        } 
        }); 
        el.addEventListener('touchmove', function(evt){ 
        if(el.offsetHeight < el.scrollHeight){ 
            evt._isScroller = true; 
        } 
        }); 
    } 
    overscroll(document.querySelector('.scroll'));//哪里需要可以局部滚动，添加一个“scroll”的class 
    document.body.addEventListener('touchmove', function(evt) { 
        if(!evt._isScroller){ 
        evt.preventDefault(); 
        } 
    });
    function buyStatus(status){
        if(status == 1){
            return "已付款"
        }else if(status == 2){
            return "已发货"
        }else if(status == 3){
            return "已收货"
        }
    }
    function sellStatus(status){
        if(status == 1){
            return "待发货"
        }else if(status == 2){
            return "已发货"
        }else if(status == 3){
            return "已收货"
        }
    }
    function appEnd1(obj){
        $('#cart_ul_1').append("<li class='cart_li'><a href='/exchange/order-details-view/"+obj.id+"'><div class='lists'><div class='cart_pic'><img src='{{ env('CDN_DOMAIN_NAME').'/upload/' }}"+obj.face+"' alt='' class='cart_img' /></div><div class='cart_info'><div class='cart_tit'><p class='cart_text'>【"+obj.title+"】<span class='cart_status'>"+buyStatus(obj.status)+"</span></p></div><div class='cart_doble'><p class='cart_size'>款号："+obj.girard+"</p></div><p class='cart_style'>购买时间："+obj.created_at+"</p><div class='cart_doble'><p class='cart_money'><i>￥</i>"+(obj.total_price+obj.postage)+"</p></div></div></div></a></li>");
    }
    function appEnd2(obj){
        $('#cart_ul_2').append("<li class='cart_li'><a href='/exchange/order-details-view/"+obj.id+"'><div class='lists'><div class='cart_pic'><img src='{{ env('CDN_DOMAIN_NAME').'/upload/' }}"+obj.face+"' alt='' class='cart_img' /></div><div class='cart_info'><div class='cart_tit'><p class='cart_text'>【"+obj.title+"】<span class='cart_status'>"+sellStatus(obj.status)+"</span></p></div><div class='cart_doble'><p class='cart_size'>款号："+obj.girard+"</p></div><p class='cart_style'>购买时间："+obj.created_at+"</p><div class='cart_doble'><p class='cart_money'><i>￥</i>"+(obj.total_price+obj.postage)+"</p></div></div></div></a></li>");
    };
    $(document).ready(function(){
        /*植入页码*/
        $(".more").attr("abc",'1');
        $.ajax({
            url:"/exchange/exchange-order-list-api",
            data:{
                type:0,
                page:0
            },
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            type:'get',
            dataType:'json',
            success:function(data){
                if(data.result.success){
                    if(data.content.order_list != ""){
                        $.each(data.content.order_list,function(idx,obj){
                            appEnd1(obj);
                        });
                        $('.cart_ul_1').show();
                        if(data.content.order_list.length >5){
                            $('.more').show();
                        }
                    }else{
                        $('.more').hide();
                        $('.lis_em').show();
                        $('.lis_wrods').text('购买订单为空');
                    }
                }
            }
        });
    });
    // function pullUpAction(){
    //     var skip=$(".more").attr("abc");
    //     $.ajax({
    //         url: '/exchange/exchange-order-list-api',
    //         type: 'get',
    //         headers: {'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')},
    //         data: {
    //             type:type,
    //             page:skip
    //         },
    //         dataType: 'json',
    //         success: function (data) {
    //             if(data.result.success == true){
    //                 $(".more").attr("abc",data.content.page);
    //                 if(type == 0){
    //                     $.each(data.content.order_list,function(idx,obj){
    //                         appEnd1(obj);
    //                     });
    //                 }else if(type == 1){
    //                     $.each(data.content.order_list,function(idx,obj){
    //                         appEnd2(obj);
    //                     });
    //                 }

    //                 myscroll.refresh();
    //             }
    //         }
    //     });
    // }
    $('#nav_li_sell').click(function(){
        var that_ = this;
        type = 0;
        $('.lis_wrods').text('去库存订单为空');
        if($(this).attr('class') == 'nav_li'){
            $(that_).addClass('on checkout');
            $(that_).siblings('#nav_li_buy').removeClass('on');
            $('#cart_ul_1').hide();
            $('#cart_ul_2').show();
            $.ajax({
                url:"/exchange/exchange-order-list-api",
                data:{
                    type:1,
                    page:page
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'get',
                dataType:'json',
                success:function(data){
                    if(data.result.success == true){
                        if(data.content.order_list != ""){
                            $.each(data.content.order_list,function(idx,obj){
                                appEnd2(obj);
                            });
                            if(data.content.order_list.length >5){
                                $('.more').show();
                            }
                            $('.lis_em').hide();
                        }else{
                            $('.more').hide();
                            $('.lis_em').show();
                        }
                        // myscroll.refresh();
                    }
                    
                }
            });
        }else if($(this).attr('class') == 'nav_li checkout'){
            $(that_).addClass('on');
            $(that_).siblings('#nav_li_buy').removeClass('on');
            $('#cart_ul_1').hide();
            $('#cart_ul_2').show();
            if($('#cart_ul_2').children().length == 0){
                $('.lis_em').show();
            }else{
                $('.lis_em').hide();
            }
            if($('#cart_ul_2').children().length > 5){
                $('.more').show();
            }else{
                $('.more').hide();
            }
        }else{
            return false;
        }
    });
    $('#nav_li_buy').click(function(){
        $('.lis_wrods').text('购买订单为空');
        type = 1;
        if($(this).attr('class') == 'nav_li'){
            if($('#cart_ul_1').children().length != 0){
                $('.lis_em').hide();
            }else{
                $('.lis_em').show();
            }
            $(this).addClass('on');
            $(this).siblings('#nav_li_sell').removeClass('on');
            $('#cart_ul_2').hide();
            $('#cart_ul_1').show();
            if($('#cart_ul_2').children().length > 5){
                $('.more').show();
            }else{
                $('.more').hide();
            }
        }else{
            return false;

        }
    });
    $(document).on('click','.close-for-goods',function() {
        $('.delDiv').show();
        $('.mask').show();
        var orderNum = $('.close-for-goods').attr('abc');
        $('#btnDelTrue').attr('abc',orderNum);
    });
    $('#btnDelTrue').click(function(){
        var orderNum = $(this).attr('abc');
        $.ajax({
            url:"/customer/update-goods-status",
            data:{
                id:orderNum
            },
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
            },
            type:'POST',
            dataType:'json',
            success:function(data){
                $('.delDiv').hide();
                $('.mask').hide();
                for(var i = 0;i < $('.close-for-goods').length;i++){
                    if($('.close-for-goods').eq(i).attr('abc')==orderNum){
                        $('.close-for-goods').eq(i).remove();
                    }
                }
            }
        });   
    });
    $('#btnCancel').click(function(){
      $('.delDiv').hide();
      $('.mask').hide();
    });
</script>
</html>
